package com.qf.purchasing.controller;

import com.github.pagehelper.PageInfo;
import com.qf.common.base.result.RespResult;
import com.qf.purchasing.qo.ApplyQO;
import com.qf.purchasing.service.ApplyService;
import com.qf.purchasing.vo.ApplyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Apply")
//类上，tags=模块名
@Api(tags = "采购申请")
public class ApplyController {
    @Resource
    private ApplyService applyService;

    @GetMapping("/list")
    @ApiOperation("根据条件分页查询采购申请")
    @ApiImplicitParams({
            //                参数名，       参数说明，         是否必填， 参数请求类型：query,header,path  参数数据类型，   参数默认值           示例
            @ApiImplicitParam(name = "page", value = "当前页数", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "1", example = "page=1"),
            @ApiImplicitParam(name = "size", value = "展示量", required = false, paramType = "query", dataType = "java.lang.Integer", defaultValue = "5"),
            @ApiImplicitParam(name = "title", value = "搜索标题", required = false, paramType = "query", dataType = "java.lang.String"),
            @ApiImplicitParam(name = "startTime", value = "开始日期", required = false, paramType = "query", dataType = "java.lang.String"),
            @ApiImplicitParam(name = "endTime", value = "结束日期", required = false, paramType = "query", dataType = "java.lang.String"),

    })
    public RespResult<PageInfo<ApplyVO>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size, @RequestParam(required = false) String title,
                                              @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        return applyService.query(page, size, title, startTime, endTime);
    }

    @PostMapping("/insert")
    @ApiOperation("添加采购申请")
    public RespResult<String> addApply(ApplyQO applyQO) {
        return applyService.addApplyService(applyQO);
    }

    @PutMapping("/delete")
    @ApiOperation("删除采购申请记录")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "applyIds", value = "采购申请id数组", required = true)
    )
    public RespResult<String> deleteApplys(int[] applyIds) {
        return applyService.deleteApplyByIds(applyIds);
    }

    @PutMapping("/update")
    @ApiOperation("修改采购申请记录")
    public RespResult<String> modifyApply(ApplyQO applyQO) {
        return applyService.modify(applyQO);
    }

    @GetMapping("/select")
    @ApiOperation("根据id查询申请记录")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "applyId", value = "采购申请id", required = true)
    )
    public RespResult<ApplyVO> queryApplyById(int applyId) {
        return applyService.selectApplyById(applyId);
    }

    @PutMapping("/recall")
    @ApiOperation("撤回功能")
    public RespResult<String> recall() {
        return applyService.recallSchedule();
    }

}
